Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

google_storage_bucket: fix custom_placement_config values not normalized #18456

Conversation

modular-magician
Copy link
Collaborator

Resolves #18035

Solution was to use StateFunc which converts the values in data_locations to be set as uppercase before storing into state. However as stated in the linked issue, there's a known problem with SDK that when using StateFunc in a nested attribute such as type.Set it will add the new value instead of replacing.

But by ignoring values in data_locations when expanding that aren't all capitalized, we can ensure that the final state will only include what we specified in StateFunc

for _, raw := range l {
		if raw.(string) == strings.ToUpper(raw.(string)) {
			req = append(req, raw.(string))
		}
	}
}

test output:
TestAccStorageBucket_dualLocation_lowercase - newly added test

(base) ┌─(~/Dev/terraform-provider-google)───────────────────────────────────────(mau@mau-JKDT676NCP:s008)─┐
└─(14:40:36 on main ✹)──> envchain GCLOUD make testacc TEST=./google/services/storage TESTARGS='-run=TestAccStorageBucket_dualLocation_lowercase'                                                    ──(Mon,Jun10)─┘
TF_ACC=1 TF_SCHEMA_PANIC_ON_ERROR=1 go test ./google/services/storage -v -run=TestAccStorageBucket_dualLocation_lowercase -timeout 240m -ldflags="-X=github.com/hashicorp/terraform-provider-google/version.ProviderVersion=acc"
=== RUN   TestAccStorageBucket_dualLocation_lowercase
=== PAUSE TestAccStorageBucket_dualLocation_lowercase
=== CONT  TestAccStorageBucket_dualLocation_lowercase
--- PASS: TestAccStorageBucket_dualLocation_lowercase (20.90s)
PASS
ok      github.com/hashicorp/terraform-provider-google/google/services/storage  22.114s

TestAccStorageBucket_dualLocation_versionChange - newly added test to ensure that behavior for user doesn't change:

(base) ┌─(~/Dev/terraform-provider-google)───────────────────────────────────────(mau@mau-JKDT676NCP:s008)─┐
└─(12:10:48 on main ✹)──> envchain GCLOUD make testacc TEST=./google/services/storage TESTARGS='-run=TestAccStorageBucket_dualLocation_versionChange'
TF_ACC=1 TF_SCHEMA_PANIC_ON_ERROR=1 go test ./google/services/storage -v -run=TestAccStorageBucket_dualLocation_versionChange -timeout 240m -ldflags="-X=github.com/hashicorp/terraform-provider-google/version.ProviderVersion=acc"
=== RUN   TestAccStorageBucket_dualLocation_versionChange
--- PASS: TestAccStorageBucket_dualLocation_versionChange (48.35s)
PASS

TestAccStorageBucket_dualLocation:

(base) ┌─(~/Dev/terraform-provider-google)──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────(mau@mau-JKDT676NCP:s008)─┐
└─(14:48:58 on main ✹)──> envchain GCLOUD make testacc TEST=./google/services/storage TESTARGS='-run=TestAccStorageBucket_dualLocation'                                                              ──(Mon,Jun10)─┘
TF_ACC=1 TF_SCHEMA_PANIC_ON_ERROR=1 go test ./google/services/storage -v -run=TestAccStorageBucket_dualLocation -timeout 240m -ldflags="-X=github.com/hashicorp/terraform-provider-google/version.ProviderVersion=acc"
=== RUN   TestAccStorageBucket_dualLocation
=== PAUSE TestAccStorageBucket_dualLocation
=== RUN   TestAccStorageBucket_dualLocation_lowercase
=== PAUSE TestAccStorageBucket_dualLocation_lowercase
=== RUN   TestAccStorageBucket_dualLocation_rpo
=== PAUSE TestAccStorageBucket_dualLocation_rpo
=== CONT  TestAccStorageBucket_dualLocation
=== CONT  TestAccStorageBucket_dualLocation_rpo
=== CONT  TestAccStorageBucket_dualLocation_lowercase
--- PASS: TestAccStorageBucket_dualLocation_lowercase (21.61s)
--- PASS: TestAccStorageBucket_dualLocation (23.27s)
--- PASS: TestAccStorageBucket_dualLocation_rpo (49.14s)
PASS
ok      github.com/hashicorp/terraform-provider-google/google/services/storage  50.278s

Release Note Template for Downstream PRs (will be copied)

storage: fixed `custom_placement_config` values not normalized in `google_storage_bucket`

Derived from GoogleCloudPlatform/magic-modules#10936

…malized (hashicorp#10936)

[upstream:4c0b1d9ce480bb5a8f56c0643da68e1415c147cf]

Signed-off-by: Modular Magician <magic-modules@google.com>
@modular-magician modular-magician merged commit 71813de into hashicorp:main Jun 17, 2024
4 checks passed
Copy link

I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 20, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bucket custom placement config values not normalised causing replacement on every apply
1 participant